package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.EmployeeDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.List;

/*
 * 员工管理的mapper
 * mapper层的作用：
 *  执行对应的sql语句查询数据库里的数据
 * */
@Mapper
public interface EmployeeMapper {
    /**
     * 根据用户名查询员工
     *
     * @param username
     * @return
     * @info 执行sql语句根据用户名查询employee表中是否有对应的用户
     */
    @Select("select * from employee where username = #{username}")
    public Employee getByUsername(String username);


    /**
     * 添加员工
     *
     * @param employee
     * @return void
     * @info 执行sql语句往employee表中添加员工
     */
    @Insert("insert into employee (name,username,password,phone,sex,id_number,status,create_time,update_time,create_user,update_user) values (#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    public void insertEmployee(Employee employee);

    /**
     * 查询所有员工(支持分页查询)
     *
     * @param void
     * @return Page<Employee>
     * @info 执行sql语句往employee表中查询所有员工
     */
    public Page<Employee> selectAllEmployee(String name);

    /**
     * 删除员工
     *
     * @param void
     * @return void
     * @info 执行sql语句往employee表中删除员工
     */
    @Delete("delete from employee where id=#{id}")
    public void deleteEmployeeById(Long id);

    /**
     * 修改员工的启用或者禁用状态
     *
     * @param status
     * @param id
     * @return void
     * @info 执行sql语句往employee表中更新员工
     */
    @Update("update employee set status=#{status},update_time=#{updateTime},update_user=#{updateUser} where id=#{id}")
    public void updateEmployeeStatusById(Employee employee);

    /**
     * 根据员工id查询员工
     *
     * @param id
     * @return
     * @info 执行sql语句根据员工id查询employee表中是否有对应的用户
     */
    @Select("select * from employee where id=#{id}")
    public Employee selectEmployeeById(Long id);

    /**
     * 编辑员工
     *
     * @param employee
     * @return
     * @info 执行sql语句根据员工id往employee数据表中修改员工
     */
    public void updateEmployee(Employee employee);
}
